#include "Global.h"

Global::Global(void){}
Global::~Global(void){}

Directx				*Global::_Directx			= new Directx();
RECT	            Global::Screen;
BackGround			*Global::BG					= new BackGround();
Loadfile			*Global::LF					= new Loadfile();
Simon				*Global::SI					= new Simon();
whip				*Global::roi				= new whip();
Collision			*Global::collision			= new Collision();
ListObject			*Global::listObj			= new  ListObject();
DynamicManager		*Global::dynamicManager		= new DynamicManager();
list<Static*>		Global::listBG;
list<Static*>		Global::listStaticObj;
list<Static*>		Global::listStaticObjRender;
BinaryTree			*Global::binaryTree			= new BinaryTree();
int					 Global::mapWidth			= 0;
int					 Global::mapHeight			= 0;
int					 Global::maplevel			= 2;
int					Global::rows;
int					Global::cols;
int					Global::mtbg[11][176];
void Global::UpdateScreen()
{
	
	if(Global::Screen.right == Global::mapWidth)
	{
		Global::Screen.right = Global::mapWidth;
		Global::Screen.left = Global::Screen.right - SCREEN_WIDTH;
		
	}
	else if (Global::SI->rectDraw.left > SCREEN_WIDTH/2 )
	{
		Global::Screen.left = Global::SI->rectDraw.left - SCREEN_WIDTH/2;
		Global::Screen.right = Global::Screen.left + SCREEN_WIDTH;
	}
}
void Global::RestartMap()
{
	Global::Screen.left		= 0;
	Global::Screen.top		= 0;
	Global::Screen.right	= SCREEN_WIDTH;
	Global::Screen.bottom	= SCREEN_HEIGHT;
	Global::listStaticObj.clear();
	Global::listStaticObjRender.clear();
	
	binaryTree->ReadBinaryTreeFormFile(Global::maplevel);
	binaryTree->Deserialize();

}
bool Global::CheckPointInRect( int x, int y, RECT rect )
{
	if ((x >= rect.left) &&
		(x < rect.right) &&
		(y >= rect.top) &&
		(y < rect.bottom))
		return true;
	return false;
}

bool Global::CheckRectInRect( RECT mainRect, RECT checkRect )
{
	return !(mainRect.left + mainRect.right < checkRect.left || 
		mainRect.left > checkRect.left + checkRect.right || 
		mainRect.top + mainRect.bottom < checkRect.top || 
		mainRect.top > checkRect.top + checkRect.bottom);
}